package com.framework.modules.app.controller;

import java.util.Arrays;
import java.util.Map;

import com.framework.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.framework.modules.base.entity.PostsEntity;
import com.framework.modules.base.service.PostsService;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 用户动态
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-18 16:46:41
 */
@RestController
@RequestMapping("app/posts")
@Api(tags = "PostsController")
public class PostsController {
    @Autowired
    private PostsService postsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
        @RequiresPermissions("app:posts:list")
        @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = postsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
        @RequiresPermissions("app:posts:info")
        @ApiOperation("info")
    public R info(@PathVariable("id") Integer id){
        PostsEntity posts = postsService.selectById(id);

        return R.ok().put("posts", posts);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        @RequiresPermissions("app:posts:save")
        @ApiOperation("save")
    public R save(@RequestBody PostsEntity posts){
        postsService.insert(posts);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        @RequiresPermissions("app:posts:update")
        @ApiOperation("update")
    public R update(@RequestBody PostsEntity posts){
        ValidatorUtils.validateEntity(posts);
        postsService.updateAllColumnById(posts);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        @RequiresPermissions("app:posts:delete")
        @ApiOperation("delete")
    public R delete(@RequestBody Integer[] ids){
        postsService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
